<?php
/**
 * Fang_Controller_Base
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-04-07 00:00:47
 * 修改记录: 
 * 
 * $Id: Base.php 20 2011-04-17 13:00:27Z coosuu $
 */

class Fang_Controller_Base extends Controller_Action {

    /**
     * _beforeAction
     * 系统钩子，前置执行 
     * 
     * @return void
     */
    protected function _beforeAction() {

        try {
            $this->cates = $this->listFirstLevelCate();
            $this->intro = $this->getIntro();
        } catch (Exception $e) {
            echo $e->getMessage();
        }

        $this->view->set('firstLevelCates', $this->cates);
        $this->view->set('intro', $this->intro);
        return true;
    }

    /**
     * listFirstLevelCate 
     * 
     * @return void
     */
    protected function listFirstLevelCate() {

        try {
            $cateService =& Service::factory('Cate');
            $cates = $cateService->listByParentId();

        } catch (Exception $e) {
            return $this->errorMessage($e->getMessage());
        }

        return $cates;
    }

    /**
     * getIntro 
     * 
     * @return void
     */
    protected function getIntro() {

        try {
            $introService =& Service::factory('Intro');
            $intro = $introService->get();
        } catch (Exception $e) {
            return $this->errorMessage($e->getMessage());
        }

        return $intro;
    }

    /**
     * errorMessage 
     * 
     * @param  mixed $message 
     * @return void
     */
    protected function errorMessage($message) {

        $this->view->set('message', $message);
        return $this->view->render('base/error');
    }

    /**
     * succMessage 
     * 
     * @param  mixed $message 
     * @return void
     */
    protected function succMessage($message) {

        $this->view->set('message', $message);
        return $this->view->render('base/error');
    }
}
